package com.zecan.blog.dao.converter;

import com.zecan.blog.dto.user.RegistryUserDto;
import com.zecan.blog.dto.user.UpdateUserInfoDto;
import com.zecan.blog.entity.BlogUser;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @ClassName BlogUserConverter
 * @Description
 * @date 2022/11/2 12:15
 * @Version 1.0
 */

@Mapper
public interface BlogUserConverter {
    // 获取实例
    BlogUserConverter INSTANCE = Mappers.getMapper(BlogUserConverter.class);

    /**
     * 用户注册DTO 转 entity
     *
     * @param registryUserDto 传输数据 dto
     * @return 用户数据
     */

 @Mappings({
         @Mapping(target = "password",source = "password"),
         @Mapping(target = "username",source = "username"),
         @Mapping(target = "userEmail",source = "email"),
         @Mapping(target = "emailCaptcha",source = "emailCaptcha"),
         @Mapping(target = "captchaKey",source = "captchaKey"),
 })
    BlogUser userRegConverterEntity(RegistryUserDto registryUserDto);


    /**
     * 用户更新数据dto  转 entity
     * @param updateUserInfoDto dto
     * @return
     */
    @Mappings({
            @Mapping(target = "password",source = "password"),
            @Mapping(target = "username",source = "username"),
            @Mapping(target = "userEmail",source = "email"),
            @Mapping(target = "emailCaptcha",source = "emailCaptcha"),
            @Mapping(target = "captchaKey",source = "captchaKey"),
            @Mapping(target = "userNickname",source = "nickname"),
            @Mapping(target = "userAvatarUrl",source = "avatarUrl"),
    })
    BlogUser userUpdateConverterEntity(UpdateUserInfoDto updateUserInfoDto);


    /**
     * 后台更新用户数据 dto  -> entity
     * @param userInfoDto
     * @return
     */
    @Mappings({
            @Mapping(target = "password",source = "password"),
            @Mapping(target = "username",source = "username"),
            @Mapping(target = "userEmail",source = "email"),
            @Mapping(target = "userRole",source = "roleId"),
            @Mapping(target = "userId",source = "userId"),
    })
    BlogUser bgUserUpdateConverterEntity(UpdateUserInfoDto userInfoDto);
}
